﻿<!-- html conetent -->
<meta http-equiv="X-UA-Compatible" content="IE=10" />
<meta content="text/html; charset=UTF-8; X-Content-Type-Options=nosniff" http-equiv="Content-Type"/>
<style>
    #communitiesTpl .tags {
        color: #C8973A;
    }
    .community_hand {
        cursor: pointer;
    }
    #communitiesTpl .hr_line {
        width: 100%;
        margin-top: 0px;
        position: relative;
        border: 0;
        height: 1px;
        background-color: #E0A941;
    }
    #community_no_result_max {
        position: absolute;
        z-index: 99999999;
        left: 18px;
        top: 60px;
        font-size: 14px;
        color: white;
        display: none;
    }
    #community_no_result_min {
        position: absolute;
        z-index: 99999999;
        left: 18px;
        top: 60px;
        font-size: 14px;
        color: white;
        display: none;
    }
    #communitiesTpl .community_no_result_p{
        line-height: 18px;
        font-size: 14px;
        color: white;
        text-align: center;
        width: 728px;
        margin-top: 25px;
        padding-left: 10px;
        overflow:hidden;
        text-overflow:ellipsis;
        word-break:break-word;
        word-wrap:break-word;
        white-space:nowap;
    }
    #communitiesTpl .comm_search{
        position:absolute;
        background-color: white;
        width:13px;
        height:12px;
        margin-top:4px;
        padding-left: 3px;
        padding-top: 3px;
        left:310px;
        z-index:99;
    }
</style>
<!--<script src="js/contact.api.js"></script>-->
<script src="js/multi.select.func.js"></script>
<!--<script src="js/community.api.js"></script>-->
<div id="communitiesTpl">
    <div class="ct_row">
        <!-- header -->
        <div id="communities_panel_header" class="ct_header">Communities
            <i id="communities_panel_resize" class="main_common_f_13_13 community_panel_resize right wp_mt_3 wp_mr_5 community_hand" title="Expand" onclick=''></i>
        </div>
        <div class="ct_warp">
            <div class="ct_button">
                <button id="create_button" onclick="communitiesCreateWinFunc.open();" type='button' class="k-button">Create</button>
                <ul style="list-style: none;" class="wp_fz_12 right">
                    <li class="right community_hand" onclick=""><i id="communities_search_icon" class="main_common_g_11_11 ct_showSearchForm" title="Search"></i></li>
                    <li class="right community_hand" onclick="">
                        <i id="communities_view_all" class="main_common_e_11_11  wp_mr_20 ct_swithListBtn" title="View Other Communities"></i>
                        <i id="communities_view_mine" class="main_common_back_11_11  wp_mr_20 ct_swithMaxBtn" style="display: none" title="View My Communities"></i>
                    </li>
                </ul>
            </div>
            <!--<img id="community_tooltip_img" src="imgs/begancommunity.png" style="display:none;margin-top: -10px;">-->
            <span id="community_no_data_min" class="wp_fz_12" style="display:none;width: 180px">
				<ul style="color: #ffffff;">
                    <li>You are not part of any communities yet. You can:</li>
                    <li class="wp_ml_10 wp_mr_15">1. Click "+" to view the communities to join.</li>
                    <li class="wp_ml_10 wp_mr_15">2. Click "Create" to create a community of your own.</li>
                </ul>
			</span>
            <span id="community_no_data_max" class="wp_fz_12" style="display:none;width: 720px">
				<ul style="color: #ffffff;text-align: center">
                    <li>You are not part of any communities yet. You can:</li>
                    <li class="wp_mr_15" style="text-align: left;margin-left: 250px">1. Click "+" to view the communities to join.</li>
                    <li class="wp_mr_15" style="text-align: left;margin-left: 250px">2. Click "Create" to create a community of your own.</li>
                </ul>
			</span>
            <span id="community_no_data_other" class="wp_fz_12" style="display:none;width: 720px">
				<ul style="color: #ffffff;text-align: center">
                    <li>There are no communities available for you to join. Click "<=" to go back to "My Communities" view.</li>
                </ul>
			</span>
        </div>
        <div class="ct_searchFrm left wp_h_20">
            <div class="wp_ml_10">
                <span>Keywords </span>
                <span class="k-textbox wp_searchbar">
                    <input id="communities_search_input" type="text" maxlength=2000
                           onkeypress="if (event.keyCode == 13) {communities.doSearch()}">
                    <i class="k-icon k-i-search" title="Search" onclick="communities.doSearch();">&nbsp;</i>
                </span>
            </div>
            <hr class="apps_tools_hr wp_w_743 wp_mt_9 wp_mb_10 left">
        </div>
    </div>
    <!-- body -->
    <div class="ct_row" id="ct_entity" data-alpa-name="communityPage_alpa_search">
        <div class="ct_body ct_filterList">
            <div class="ct_warp" style="width: 713px;overflow: hidden" class="word-break">
                <span class='ct_bta community_hand' style="color: #4bb3fc" onclick="communities.back_to_all();">Back to all </span>
                <span>&nbsp;&gt;&nbsp;Showing&nbsp;<span id="community_search_result_count"></span>&nbsp;result(s) for&nbsp;<span
                        id="community_search_result_keywords" style="text-overflow:ellipsis;word-wrap:break-word;white-space:nowap;"></span></span>
            </div>
        </div>
        <div class="ct_body" id="ct_body">
        </div>
    </div>
</div>
<!-- template -->
<!-- min template -->
<script id="ct_minRowTmpl" type="text/x-kendo-template">
    <div class="ct_row wp_mb_10">
        <div class="ct_warp">
            <div style="display: none">#: data.CommunityID #</div>
            <div class="pic community_hand"
                 onclick="communities.viewMore('#: data.CommunityID #','#: data.CommunityName #')">
                <img class="wp_w_40 wp_h_40" src="#: data.imgUrl #" alt="" onerror="onDefaultThumbnailWanted(this,'C40')">
            </div>
            <div class="txt">
                <ul>
                    <li class="wp_fz_14" style="line-height: 18px;">
                        <span id="communities_min_title_#: data.CommunityID #" class="community_hand" title="#: data.CommunityName #" onclick="communities.viewMore('#: data.CommunityID #','#: data.CommunityName #')">
                            #: data.CommunityName #
                        </span>
                    </li>
                    <li class="wp_fz_12">#: data.CommunityType #</li>
                    <li class="wp_fz_12">#: data.membersCount # Member(s)</li>
                </ul>
            </div>
        </div>
    </div>
</script>
<!-- max template -->
<script id="ct_maxRowTmpl" type="text/x-kendo-template">
    <div class="ct_row wp_mt_9">
        <div class="ct_warp ct_max">
            <div style="display: none">#: data.id #</div>
            <div class="pic community_hand" onclick="communities.viewMore('#: data.id #','#: data.title #')">
                <img id="communities_max_img_#: data.id #" class="wp_w_40 wp_h_40" src="#: data.icon #" onerror="onDefaultThumbnailWanted(this,'C40')">
            </div>
            <div class="txt">
                <ul>
                    <li class="wp_fz_14" style="line-height: 18px">
                        <span id="communities_max_title_#: data.id #" class="community_hand" title="#: data.title #" onclick="communities.viewMore('#: data.id #','#: data.title #')">
                            #: data.title #
                        </span>
                    </li>
                    #var strArray = (data.tags+'') .split(",");#
                    <li id="communities_max_tags_#: data.id #" class="wp_fz_12 tags" style="word-wrap:break-word;white-space:normal">
                        <img src="imgs/icons/tagcommunity.png" class="wp_mt_6">
                        #for (var i = 0; i < strArray.length; i++) {#
                            <span class="community_hand" style="color: \#b28634" onclick='communities.tagsClick("#:strArray[i]#")'>#:strArray[i]#</span>
                            #if(i!=strArray.length-1){#
                                ,
                            #}#
                        #}#
                    </li>
                    <li>
                        <ol>
                            #if(data!=undefined){#
                            # for(var i = 0;i < data.notes.length ; i++) { #
                            <li>
                                <div class="icon community_hand"
                                     onclick="homepageProfileWin.user_info_win_create('#: data.notes[i].fromId#')">
                                    <img class="wp_w_20 wp_h_20" src="#:data.notes[i].pic#"
                                         onerror="onDefaultThumbnailWanted(this,'I')">
                                </div>
                                <div class="desc">
                                    <div class="ct_row">
                                        <span id="communities_max_note_title_#:data.notes[i].id#" class="left  wp_fz_14 community_hand"
                                              style="max-width:560px;line-height: 18px;text-overflow:ellipsis;white-space:nowrap; overflow:hidden;"
                                              title="#: data.notes[i].title #"
                                              onclick="var cb = function () {};show_ss_topic_detail_win('community','#:data.notes[i].id#','c','#:data.id#','','',1, cb, true);">#: data.notes[i].title #</span>
                                        <span id="communities_max_note_passed_#:data.notes[i].id#" class="right wp_fz_12">#: data.notes[i].passed #</span>
                                    </div>
                                    <div class="ct_row wp_fz_12">
                                        <span id="communities_max_note_desc_#:data.notes[i].id#" class="left community_hand" style="max-width:630px;line-height: 18px;text-overflow:ellipsis;white-space:nowrap; overflow:hidden;"
                                              title="#: data.notes[i].desc #"
                                              onclick="var cb = function () {};show_ss_topic_detail_win('community','#:data.notes[i].id#','c','#:data.id#','','',1, cb, true);"  >#: data.notes[i].desc #</span>
                                    </div>
                                </div>
                            </li>
                            # }} #
                            <li>
                                <span id="communities_max_view_all_#: data.id #" class="right wp_fz_12 community_hand"
                                      onclick="communities.viewMore('#: data.id #','#: data.title #')">
                                    View All
                                </span>
                            </li>
                        </ol>
                    </li>
                </ul>
            </div>
        </div>
    </div>
    <div class="ct_row ct_line">
        <hr noshade="noshade" class="hr_line">
    </div>
</script>
<!-- list template -->
<script id="ct_litRowTmpl" type="text/x-kendo-template">
    <li>
        <div style="display: none">#: data.CommunityID #</div>
        <div class="pic community_hand" onclick="communities.viewMore('#: data.CommunityID #','#: data.CommunityName #')">
            <img class="wp_w_40 wp_h_40" src="#: data.imgUrl #" alt="" onerror="onDefaultThumbnailWanted(this,'C40')">
        </div>
        <div class="desc">
            <ol>
                <li class="wp_fz_14"
                    style="line-height: 18px;max-width:180px;text-overflow:ellipsis;white-space:nowrap; overflow:hidden;">
                    <span class="community_hand" title="#: data.CommunityName #"
                          onclick="communities.viewMore('#: data.CommunityID #','#: data.CommunityName #')">#: data.CommunityName #</span>
                </li>
                <li class="wp_fz_12">#: data.CommunityType #</li>
                <li class="wp_fz_12">#: data.membersCount # member(s)</li>
            </ol>
        </div>
    </li>
</script>
<!-- list other template -->
<script id="ct_litOtherTmpl" type="text/x-kendo-template">
    <li>
        <div style="display: none">#: data.CommunityID #</div>
        <div class="pic community_hand" onclick="community_profile_controller.initProfilePage('#: data.CommunityID #')">
            <img class="wp_w_40 wp_h_40" src="#: data.imgUrl #" alt="" onerror="onDefaultThumbnailWanted(this,'C40')">
        </div>
        <div class="desc">
            <ol>
                <li class="wp_fz_14"
                    style="line-height: 18px;max-width:180px;text-overflow:ellipsis;white-space:nowrap; overflow:hidden;">
                    <span id="communities_other_title_#: data.CommunityID #" class="community_hand" title="#: data.CommunityName #"
                          onclick="community_profile_controller.initProfilePage('#: data.CommunityID #')">#: data.CommunityName #</span>
                </li>
                <li class="wp_fz_12">#: data.CommunityType #</li>
                <li class="wp_fz_12">#: data.membersCount # member(s)</li>
            </ol>
        </div>
    </li>
</script>

<!-- customer script -->
<script>
var communities = (function () {
    var pageTpl = $('#communitiesTpl'),
        bodyTpl = $('#ct_body'),
        entyTpl = $('#ct_entity'),
        searchFrm = $('.ct_searchFrm'),
        searchBtn = $('.ct_showSearchForm'),
        frmSearchBtn = $('.ct_frmSearchBtn'),
        swithListBtn = $('.ct_swithListBtn'),
        swithMaxBtn = $('.ct_swithMaxBtn'),
        minRowTmpl = $.trim($('#ct_minRowTmpl').html()),
        maxRowTmpl = $.trim($('#ct_maxRowTmpl').html()),
        lstRowTmpl = $.trim($('#ct_litRowTmpl').html()),
        lstOtherTmpl = $.trim($('#ct_litOtherTmpl').html()),
        rowTmpl = null,
        _isList = false, // if current is list view
        _isOther = false,
        _isadd = false, // if click append
        _height = Workport.utils.getViewPort().height - 120,
        _loadingHeight = Workport.utils.getViewPort().height/2-50,
        _pagePosition = '',
        _pageNumber = 1,
        _pageSize = 20 ,
        _min = true,   // if is min window
        _key = '',
        _next = true,  // control when top is attached
        _order = '',
        _type = 0,
        maxStartCount = Math.ceil((Screen.bodyHeight - $('#wp_header').height()) / 45 * 3),
        letterSearchTool,
        commLoader,
        _search = false;
        var useragent = Workport.getBrowser();
    return{
        /**
         *initialize
         **/
        init: function () {
            rowTmpl = minRowTmpl;
            entyTpl.height(_height + 20);
            bodyTpl.css({'height': _height});
            pageTpl.appendTo('#communities');
            swithListBtn.attr('onclick', 'communities.switchMaxList()');
            swithMaxBtn.attr('onclick', 'communities.switchToMax()');
            searchBtn.attr("onclick", "communities.swithToSearch()");
            frmSearchBtn.attr("onclick", "communities.doSearch()");
            commLoader = new Workport.Loader($('#communities'),{ text:'Loading', position:'center',imgColor:'white', textCSS:{'color':'white'} })
            commLoader.show();
            Workport.CommunityAPI.getCommunityHome(function (_d) {
                commLoader.hide();
                _next = true;
                if (_d.code == 'WP1005') {
                    _next = false;
                }
                if (_d.data.length == 0) {
                    $("#community_no_data_min").show();
                } else {
                    $("#community_no_data_min").hide();
                }
                communities.render(_d.data);
                if(useragent == 'ipad'){
                    $("#ct_body").bind("scroll",function(){
                            if($("#ct_body").scrollTop() == 0){ //top
                                _next = false;
                                communities.doTop();
                            } 
                            else if($("#ct_body")[0].scrollHeight <= $("#ct_body").scrollTop() + $("#ct_body").height()){
                                _pageNumber++;
                                communities.doAppend();
                            }
                    });
                   $('#ct_body').css('overflow-y','scroll');
                } else{
                    bodyTpl.slimScroll().bind('slimscroll', function (e, pos) {
                        if ('bottom' == pos) {
                            _pageNumber++;
                            communities.doAppend();
                        }
                        if (_next && 'top' == pos) {
                            _next = false;
                            communities.doTop();
                        }
                    });
                }
            }, {pageSize: _pageSize, pagePosition: _pageNumber, key: _key, type: _type});
            var community_letter = Letter('#ct_entity', function (_letter) {
                _key = _order = _letter;
                if (_letter == 'All') {
                    _key = _order = '';
                } else if (_letter == '#') {
                    _key = _order = 'others';
                }
                if (_min == false) {
                    searchFrm.hide();
                }
                communities.letterSearch();
            }, '#c69639');
            letterSearchTool = community_letter;
            //scroll in homepage
            HomePage_Scrollable.registerZoomCallback(WPMoudleManager.getModule('communities').index, communities.switchMax, communities.switchMin);
            $('.community_panel_resize').bind({
                click: function (e) {
                    HomePage_Scrollable.zoom(WPMoudleManager.getModule('communities').index);
                }
            });
        },
        refresh: function () {
            if (!_isOther) {
//                letterSearchTool.cancleHighLight();
//                _key = '',
//                _order = '',
//                _isList = false,
                _isadd = false;
                _isOther = false;
                _next = true;
                _type = '0';
                _pageSize = 20;
                _pageNumber = 1;
                _pagePosition = '';
                bodyTpl.off('*'),
                bodyTpl.empty(),
                searchFrm.hide();
                if (_min) {
                    communities.minLoading();
                    rowTmpl = minRowTmpl;
                    Workport.CommunityAPI.getCommunityHome(function (_d) {
                        commLoader.hide();
                        if (_d.data.length == 0) {
                            if($.trim(_key)==''){
                                $("#community_no_data_min").show();
                            }else{
                                var errorMessage = "No Communities beginning with " + _key;
                                var leftvalue = '18';
                                if (_key == 'others') {
                                    errorMessage = 'No Communities beginning with #.';
                                    leftvalue = '18';
                                }
                                if(useragent == 'ipad'){
                                    var innerHtml = '<span id="community_no_result_min" style="text-align:center;top: 60px;left: ' + leftvalue + 'px; display: inline;">' + errorMessage + '</span>';
                                }else{
                                    var innerHtml = '<span id="community_no_result_min" style="text-align:center;top: 10px;left: ' + leftvalue + 'px; display: inline;">' + errorMessage + '</span>';
                                }
                                $('#ct_body').html(innerHtml);
                            }
                        } else {
                            $("#community_no_data_min").hide();
                        }
                        if ($.isArray(_d.data)) {
                            _next = true;
                            if (_d.code == 'WP1005') {
                                _next = false;
                            }
                            communities.render(_d.data);
                            _pageNumber++;
                        }
                    }, {pageSize: _pageSize, pagePosition: _pageNumber, key: _key, type: _type});
                }
                else {
                    communities.maxLoading();
                    if(_isList){
                        if($.trim($('.ct_searchFrm input:first').val())!=""){
                            communities.swithToSearch();
                            $('.ct_searchFrm input:first').val(_key);
                            communities.doSearch();
                        }
                        else{
                            _key="";
                            Workport.CommunityAPI.getCommunityHome(function (_d) {
                                commLoader.hide();
                                if (_d.data.length == 0) {
                                    $("#community_no_data_min").show();
                                } else {
                                    $("#community_no_data_min").hide();
                                }
                                if ($.isArray(_d.data)) {
                                    _next = true;
                                    if (_d.code == 'WP1005') {
                                        _next = false;
                                    }
                                    communities.render(_d.data);
                                    _pageNumber++;
                                }
                            }, {pageSize: _pageSize, pagePosition: _pageNumber, key: _key, type: _type});
                        }
                    }else{
                        rowTmpl = maxRowTmpl;
                        $(".ct_swithListBtn").show();
                        $(".ct_swithMaxBtn").hide();
                        Workport.StreamAPI.getCommunityPreview(function (_d) {
                            commLoader.hide();
                            if (_d.data.length == 0) {
                                if($.trim(_order)==''){
                                    $("#community_no_data_max").show();
                                }else{
                                    var errorMessage = "No Communities beginning with " + _order;
                                    var leftvalue = '280';
                                    if (_order == 'others') {
                                        errorMessage = 'No Communities beginning with #.';
                                        leftvalue = '280';
                                    }
                                    if(useragent == 'ipad'){
                                        var innerHtml = '<span id="community_no_result_min" style="text-align:center;top: 60px;left: ' + leftvalue + 'px; display: inline;">' + errorMessage + '</span>';
                                    }else{
                                        var innerHtml = '<span id="community_no_result_min" style="text-align:center;top: 10px;left: ' + leftvalue + 'px; display: inline;">' + errorMessage + '</span>';
                                    }
                                    $('#ct_body').html(innerHtml);
                                }
                            } else {
                                $("#community_no_data_max").hide();
                            }
                            if ($.isArray(_d.data)) {
                                _next = true;
                                if (_d.code == 'WP1005') {
                                    _next = false;
                                }
                                communities.render(_d.data);
                                _pagePosition = _d.page;
                            }
                        }, {pageSize: _pageSize, pagePosition: _pagePosition, order: _order, type: _type});
                    }
                }
            }
            else {
                _isList = true;
                _isOther = true;
                _type = 1;
                _pageSize = maxStartCount;
                _next = true;
                communities.switchMax();
                searchFrm.hide();
                communities.closeBTA();
                $(".ct_swithListBtn").hide();
                $(".ct_swithMaxBtn").show();
            }
        },
        /**
         *switch to min
         **/
        switchMin: function () {
            _search=false;
            communities.minLoading();
            letterSearchTool.cancleHighLight();
            communities.hide_tooltip();
            communities.closeBTA();
            $(".community_panel_resize").toggleClass("main_common_f_13_13 main_common_m_13_13");
            $(".community_panel_resize").attr("title",'Expand');
            _key = '',
            _order = '',
            _min = true,
            _isadd = false,
            _isList = false,
            _isOther = false,
            _next = true,
            _pageNumber = 0 ,
            _type = '0';
            _pageSize = 20;
            bodyTpl.off('*'),
            bodyTpl.empty(),
            searchFrm.hide(),
            rowTmpl = minRowTmpl;
            $(".ct_swithListBtn").show();
            $(".ct_swithMaxBtn").hide();
            Workport.CommunityAPI.getCommunityHome(function (_d) {
                commLoader.hide();
                if (_d.data.length == 0) {
                    $("#community_no_data_min").show();
                } else {
                    $("#community_no_data_min").hide();
                }
                if ($.isArray(_d.data)) {
                    _next = true;
                    if (_d.code == 'WP1005') {
                        _next = false;
                    }
                    communities.render(_d.data);
                    _pageNumber++;
                }
            }, {pageSize: _pageSize, pagePosition: _pageNumber, key: _key, type: _type});
        },
        viewMore: function (id, title) {
            var callback = function () {
                communities.refresh();
            }
            community_smartstream.exportInterface(id, title, callback);
        },
        /**
         *swith to max
         **/
        switchMax: function () {
            communities.hide_tooltip();
            if (_min) {
                $(".community_panel_resize").toggleClass("main_common_f_13_13 main_common_m_13_13");
                $(".community_panel_resize").attr("title",'Collapse');
            }
            _order = '',
            _next = true,
            _min = false,
            _isadd = false,
            _pagePosition = '',
            _pageNumber = 0,
            bodyTpl.off('*'),
            bodyTpl.empty(),
            rowTmpl = _isList ? lstOtherTmpl : maxRowTmpl;
            //for refresh other community
            if(!_isOther){
                letterSearchTool.cancleHighLight();
                _key = '';
            }else{
                _order = _key;
            }
            communities.maxLoading();
            if (!_search) {
                if (_isList) {
                    Workport.CommunityAPI.getCommunityHome(function (_d) {
                        commLoader.hide();
                        if (_d.data.length == 0) {
                            $("#community_no_data_other").show();
                        } else {
                            $("#community_no_data_other").hide();
                        }
                        if ($.isArray(_d.data)) {
                            _next = true;
                            if (_d.code == 'WP1005') {
                                _next = false;
                            }
                            communities.render(_d.data);
                            _pageNumber++;
                        }
                    }, {pageSize: _pageSize, pagePosition: _pageNumber, key: _key, type: _type});
                } else {
                    Workport.StreamAPI.getCommunityPreview(function (_d) {
                        commLoader.hide();
                        if (_d.data.length == 0) {
                            $("#community_no_data_max").show();
                        } else {
                            $("#community_no_data_max").hide();
                        }
                        if ($.isArray(_d.data)) {
                            _next = true;
                            if (_d.code == 'WP1005') {
                                _next = false;
                            }
                            communities.render(_d.data);
                            _pagePosition = _d.page;
                        }
                    }, {pageSize: _pageSize, pagePosition: _pagePosition, order: _order, type: _type});
                }
            }
        },
        /**
         *switch to max list action
         **/
        switchMaxList: function () {
            letterSearchTool.cancleHighLight();
            _search=false;
            _isList = true;
            _isOther = true;
            _type = 1;
            _key = "";
            _pageSize = maxStartCount;
            _next = true;
            _min ?  HomePage_Scrollable.zoom(WPMoudleManager.getModule('communities').index) : communities.switchMax();
            searchFrm.hide();
            communities.closeBTA();
            communities.hide_tooltip();
            $(".ct_swithListBtn").hide();
            $(".ct_swithMaxBtn").show();
        },
        /**
         *switch to max action
         **/
        switchToMax: function () {
            _search=false;
            _isList = false;
            _next = true;
            _isOther = false;
            _key = "";
            _type = 0;
            _pageSize = 20;
            searchFrm.hide();
            letterSearchTool.cancleHighLight();
            communities.switchMax();
            communities.closeBTA();
            $(".ct_swithListBtn").show();
            $(".ct_swithMaxBtn").hide();
        },
        /**
         *when letter search call this
         **/
        letterSearch: function () {
            _search=false;
            if(_type=='0'){
                _isList=false;
            }
            communities.closeBTA();
            _isadd = false,
            _pageNumber = 0 ,
            _pagePosition = '',
            _next = true,
            bodyTpl.off('*'),
            bodyTpl.empty(),
            $('.ct_searchFrm input:first').val('');
            if (_min || _isList) {
                commLoader.setOptions({textCSS:{'display':'inline','color':'white'}});
                commLoader.setPosition('center');
                commLoader.show();
                Workport.CommunityAPI.getCommunityHome(function (_d) {
                    commLoader.hide();
                    if (_d.data.length == 0) {
                        var errorMessage = "No Communities beginning with " + _key;
                        var leftvalue = '18';
                        if (_isList) {
                            leftvalue = '280';
                        }
                        if (_key == '') {
                            errorMessage = 'No Communities found.';
                            leftvalue = '55';
                            if (_isList) {
                                leftvalue = '320';
                            }
                        } else if (_key == 'others') {
                            errorMessage = 'No Communities beginning with #.';
                            leftvalue = '18';
                            if (_isList) {
                                leftvalue = '280';
                            }
                        }
                        if(useragent == 'ipad'){
                            var innerHtml = '<span id="community_no_result_min" style="text-align:center;top: 60px;left: ' + leftvalue + 'px; display: inline;">' + errorMessage + '</span>';
                        }else{
                            var innerHtml = '<span id="community_no_result_min" style="text-align:center;top: 10px;left: ' + leftvalue + 'px; display: inline;">' + errorMessage + '</span>';
                        }
                        $('#ct_body').html(innerHtml);
                    }
                    if ($.isArray(_d.data)) {
                        _next = true;
                        if (_d.code == 'WP1005') {
                            _next = false;
                        }
                        communities.render(_d.data);
                        _pageNumber++;
                    }
                }, {pageSize: _pageSize, pagePosition: _pageNumber, key: _key, type: _type});
            } else {
                communities.maxLoading();
                rowTmpl = maxRowTmpl;
                $(".ct_swithListBtn").show();
                $(".ct_swithMaxBtn").hide();
                Workport.StreamAPI.getCommunityPreview(function (_d) {
                    commLoader.hide();
                    if (_d.data.length == 0) {
                        var errorMessage = "No Communities beginning with " + _key;
                        var leftvalue = '280';
                        if (_key == '') {
                            errorMessage = 'No Communities found.';
                            leftvalue = '320';
                        } else if (_key == 'others') {
                            errorMessage = 'No Communities beginning with #.';
                            leftvalue = '280';
                        }
                        if(useragent == 'ipad'){
                            var innerHtml = '<span id="community_no_result_min" style="text-align:center;top: 60px;left: ' + leftvalue + 'px; display: inline;">' + errorMessage + '</span>';
                        }else{
                            var innerHtml = '<span id="community_no_result_min" style="text-align:center;top: 10px;left: ' + leftvalue + 'px; display: inline;">' + errorMessage + '</span>';
                        }
                        $('#ct_body').html(innerHtml);
                    }
                    if ($.isArray(_d.data)) {
                        _next = true;
                        if (_d.code == 'WP1005') {
                            _next = false;
                        }
                        communities.render(_d.data);
                        _pagePosition = _d.page;
                    }
                }, {pageSize: _pageSize, pagePosition: _pagePosition, order: _order, type: _type});
            }
        },
        /**
         *1,max it
         *2,show search form
         **/
        swithToSearch: function () {
            if (_min) {
                HomePage_Scrollable.zoom(WPMoudleManager.getModule('communities').index);
            }
            _min = false;
            _next = true;
            $(".ct_searchFrm input").val("");
            communities.closeBTA();
            $("#community_no_result_max").remove();
            $("#community_no_result_min").remove();
            $('#ct_body').find("p:first").remove();
            searchFrm.toggle();
            communities.hide_tooltip();
        },
        /**
         * 1,if min or max list then call getcommunityHome api to append
         **/
        doAppend: function () {
            communities.appendLoading();
            _isadd = true;
            if (!_next) {
                commLoader.hide();
                return;
            }
            if (_min || _isList) {
                Workport.CommunityAPI.getCommunityHome(function (_d) {
                    commLoader.hide();
                    if ($.isArray(_d.data)) {
                        _next = true;
                        if (_d.code == 'WP1005') {
                            _next = false;
                        }
                        communities.render(_d.data);
                    }
                }, {pageSize: _pageSize, pagePosition: _pageNumber, key: _key, type: _type})
            } else {
                Workport.StreamAPI.getCommunityPreview(function (_d) {
                    commLoader.hide();
                    if (_d.data.length) {
                        _next = true;
                        if (_d.code == 'WP1005') {
                            _next = false;
                        }
                        communities.render(_d.data);
                        _pagePosition = _d.page;
                    }
                }, {pageSize: _pageSize, pagePosition: _pagePosition, order: _order, type: _type});
            }
        },
        /**
         *waiting api
         **/
        doTop: function () {
            _pageNumber = 0 ,
            _pagePosition = '',
            _next = true;
        },
        /**
         *render template
         **/
        render: function (_data) {
            var tpl = kendo.template(rowTmpl, {useWithBlock: false});
            var arr = new Array();
            //if is list view and the first time  then add this before
            if (_isList && !_isadd) {
                arr.push('<div class="ct_warp ct_list"><ul>');
            }
            $.map(_data, function (_elem) {
                arr.push(tpl(_elem));
            });
            //if is list view and the first time  then add this after
            if (_isList && !_isadd) {
                arr.push('</ul></div>');
            }
            if (_isadd && _isList) {
                $(arr.join('')).appendTo('#ct_body div ul');
            }
            else {
                $(arr.join('')).appendTo('#ct_body');
            }
            arr.length = 0;
            if ($.trim(_key) != "" && ($.trim(_order) == "")) {
                $("#communitiesTpl").find(".ct_body").find(".desc").find(".wp_fz_14").highlight(_key);
            }
            if(useragent !='ipad'){
                bodyTpl.slimScroll({
                    width: '100%',
                    wheelStep: 20,
                    disableFadeOut: true,
                    height: _height + 'px'
                });
            }
        },
        doSearch: function () {
            letterSearchTool.cancleHighLight();
            _pagePosition = '1',
            _order = '',
            _next = true,
            _isadd = false,
            rowTmpl = lstRowTmpl;
//            _key = encodeURI($('.ct_searchFrm input:first').val());
            _key = $('.ct_searchFrm input:first').val();
            var key = $.param({key: _key}).substring(4);
            var searchBar = $('.ct_searchFrm input');
            searchBar.on('input',function(e){
                searchBar.data('kendoTooltip').hide();
            });
            if ($.trim($('.ct_searchFrm input').val()) == "") {
                searchBar.kendoTooltip({
                    content: 'Please input the keywords.',
                    position: "right",
                    hide: function() {
                        searchBar.data('kendoTooltip').destroy();
                    }
                });
                searchBar.data('kendoTooltip').show();
                return;
            }
            bodyTpl.off('*'),
            bodyTpl.empty();
            _type = "0";
            if (_isOther) {
                _type = '1';
                rowTmpl = lstOtherTmpl;
            }
            _isList = true;
            communities.closeBTA();
            communities.maxLoading();
            Workport.CommunityAPI.search(function (_d) {
                commLoader.hide();
                if ($.isArray(_d.data)) {
                    $('.ct_filterList').show();
                    $('#community_search_result_keywords').text($('.ct_searchFrm input').val());
                    $('#community_search_result_count').text(_d.data.length);
                    if (_d.code == "WP1003") {
                        var errorMessage = "No results for " + $('.ct_searchFrm input').val() + ".";
                        var leftvalue = '325';
//                        var innerHtml = '<span id="community_no_result_min" class="text-overflow" style=" float:left;text-align:center;top: 10px;left: ' + leftvalue + 'px; display: inline;">' + errorMessage + '</span>'+
                        var innerHtml ='<p class="community_no_result_p">No results for <span>'+$('.ct_searchFrm input').val()+'</span>.</p>';
                        $('#ct_body').html(innerHtml);
                        $('#ct_body').find("p:first").highlight($.trim($('.ct_searchFrm input').val()));
                    } else {
                        _next = true;
                        if (_d.code == 'WP1005') {
                            _next = false;
                        }
                        communities.render(_d.data);
                        _pagePosition = _d.page;
                    }
                }
            }, {pageSize: _pageSize, pagePosition: _pagePosition, key: key, type: _type});
        },
        closeBTA: function () {
            $('.ct_filterList').hide();
        },
        back_to_all: function () {
            if (_isOther) {
                communities.switchMaxList();
            } else {
                communities.switchToMax();
            }
        },
        hide_tooltip: function () {
            $("#community_no_data_min").hide();
            $("#community_no_data_max").hide();
            $("#community_no_data_other").hide();
        },
        tagsClick : function (tags) {
            _search = true;
            communities.swithToSearch();
            searchFrm.show();
            $('.ct_searchFrm input:first').val(tags);
            communities.doSearch();
        },
        minLoading:function (){
            $('#communities').width('256px');
            commLoader.setOptions({textCSS:{'display':'inline','color':'white'}});
            commLoader.setPosition('center');
            commLoader.show();
        },
        maxLoading:function (){
            $('#communities').width('768px');
            commLoader.setOptions({textCSS:{'display':'inline','color':'white'}});
            commLoader.setPosition('center');
            commLoader.show();
        },
        appendLoading:function () {
            commLoader.setOptions({textCSS:{'display':'none'}});
            commLoader.setPosition('down');
            commLoader.show();
        }
    };
})();
communities.init();
</script>